package util

import (
	"fmt"
	"strings"
	"sync/atomic"
	"time"
)

// Revert 字符串倒序输出
func Revert(v string) string {
	result := []rune(v)
	for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
		result[i], result[j] = result[j], result[i]
	}
	return string(result)
}

// Star 手机号✳处理
func Star(v string) string {
	if len(v) <= 3 {
		return ""
	} else if len(v) <= 7 {
		return strings.Replace(v, v[3:], "***", -1)
	} else {
		return strings.Replace(v, v[3:len(v)-4], "***", -1)
	}
}

func NewOrderGenerator(machineID string, sequence uint32) string {
	now := time.Now()

	// 时间部分：YYMMDDHHMMSS
	timePart := now.Format("060102150405")

	// 序列号 (0-9999)
	seq := atomic.AddUint32(&sequence, 1) % 10000

	return fmt.Sprintf("%s%s%04d", timePart, machineID, seq)
}
